fix: enable Docker API version negotiation#545
Conversation
bbdd25e to
e10aa21
Compare
Without WithAPIVersionNegotiation(), the Docker client defaults to the API version compiled into the moby/moby library (currently v1.53). When connecting to older Docker daemons that only support up to e.g. v1.43, this causes "client version 1.53 is too new" errors. Adding WithAPIVersionNegotiation() makes the client ping the daemon first and downgrade to the daemon's supported API version, matching the behavior of the Docker CLI itself. Signed-off-by: Jarek Krochmalski <jkrochmalski@gmail.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
e10aa21 to
e1d7ffe
Compare
|
I'm confused how this could make a difference, this option is deprecated upstream and auto-negotiation is on by default. There are conditions that disable negotiation though, such as setting Can you double check your findings? Since the option that you added is a |
|
Yes, this option is no longer needed, and now enabled by default; the old ( |
Summary
client.WithAPIVersionNegotiation()to the Docker client options inGetClient()Problem
The Docker client in
internal/docker/client.gousesclient.FromEnvbut does not enable API version negotiation. This means the client defaults to the API version compiled into themoby/mobylibrary (currentlyv1.53).When stereoscope connects to an older Docker daemon — for example one that only supports API
v1.43— the daemon rejects requests with:This breaks tools like grype when scanning images on hosts running older Docker versions (e.g. Docker 25.x, 26.x, Synology DSM).
Fix
Adding
client.WithAPIVersionNegotiation()makes the client ping the daemon on first request and automatically downgrade to the daemon's supported API version. This matches the behavior of the Docker CLI itself and grype's own Docker client incmd/grype/cli/commands/completion.go, which already usesWithAPIVersionNegotiation().Test plan
go build ./internal/docker/compiles successfullygo test ./internal/docker/passes